package com.kyleromano.disgaea;

import java.io.IOException;

import com.kyleromano.disgaea.dataType.ParentJob;
//import com.kyleromano.disgaea.dataType.Classes;
import com.kyleromano.disgaea.dataType.TileSheet;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;

public class Character {
	private String		charName;
	private int			jobParent;
	private int			charClass;
	//private String		charClassString;
	private TileSheet	portrait;
	private TileSheet	icon;
	private int 		charLevel = 1;
	private String		weapons;
	
	/**
	 * Constructor :  baby!
	 * 
	 * @param charName Character's name
	 * @param charClass Character's class :  e.g. Thief :  Rogue :  Trickster
	 * @param jobParent Character's class parent e.g. Warrior :  Valkyrie :  Thief :  Archer
	 * @param level Character's level
	 * @param stream InputStream to the resource
	 * 
	 */
	public Character(String charName, int charClass, int jobParent, int level, Context context)
			throws IOException
	{
		this.charName = charName;
		this.charLevel = level;
		this.charClass = charClass;
		this.jobParent = jobParent;
		//this.charClassString = Classes.getJobString(charClass);
		updatePortrait(context.getAssets());
		updateIcon(context.getAssets());
		setProficiencies(context);
	}

	//The Getters
	public String	 getName()				{ return charName;  }
	public int		 getJobParent()			{ return jobParent; }
	public int		 getLevel()				{ return charLevel; }
	public int		 getCharClass()			{ return charClass; }
	public String	 getProficiencies()		{ return weapons;	}
	//public String	 getCharClassString()	{ return charClassString; }
	
	//The Setters
	public void		setName(String name)	{ charName = name;  }
	public void		setCharClass(int cCl)	{ charClass = cCl;  }//charClassString = Classes.getJobString(charClass); }
	public void		setLevel(int level)		{ charLevel = level; }
	public void		setJobParent(int job, Context context) {
		jobParent = job;
		setProficiencies(context);
		}
	
	/**
	 * Define weapon proficiencies or magichange type
	 */
	private void setProficiencies(Context context) {
		switch(jobParent) {
		case ParentJob.WARRIOR		:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sSword) + ", " +
			context.getString(R.string.sSpear) + ", " +
			context.getString(R.string.sAxe);
			break;
		case ParentJob.VALKYRIE		:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sSword) + ", " +
			context.getString(R.string.sSpear) + ", " +
			context.getString(R.string.sBow);
			break;
		case ParentJob.WITCH		:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sStaff);
			break;
		case ParentJob.MAGICIAN		:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sStaff);
			break;
		case ParentJob.HEALER		:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sBow) + ", " +
			context.getString(R.string.sStaff);
			break;
		case ParentJob.ARCHER		:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sSpear) + ", " +
			context.getString(R.string.sBow);
			break;
		case ParentJob.GUNNER		:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sFist) + ", " +
			context.getString(R.string.sGun);
			break;
		case ParentJob.ARMORKNIGHT	:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sSpear) + ", " +
			context.getString(R.string.sAxe);
			break;
		case ParentJob.THIEF		:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sBow) + ", " +
			context.getString(R.string.sGun);
			break;
		case ParentJob.NINJA		:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sFist) + ", " +
			context.getString(R.string.sSword) + ", " +
			context.getString(R.string.sStaff);
			break;
		case ParentJob.SAMURAI		:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sSword) + ", " +
			context.getString(R.string.sBow);
			break;
		case ParentJob.BEASTMASTER	:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sSpear) + ", " +
			context.getString(R.string.sBow) + ", " +
			context.getString(R.string.sAxe);
			break;
		case ParentJob.SORCERER		:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sSpear) + ", " +
			context.getString(R.string.sStaff);
			break;
		case ParentJob.BOUNCER		:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sFist) + ", " +
			context.getString(R.string.sGun);
			break;
		case ParentJob.PROFESSOR	:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sGun) + ", " +
			context.getString(R.string.sStaff);
			break;
		case ParentJob.MAGICKNIGHT	:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sSword) + ", " +
			context.getString(R.string.sStaff);
			break;
		case ParentJob.MASKEDHERO	:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sFist) + ", " +
			context.getString(R.string.sGun);
			break;
		case ParentJob.ONMYOMONK	:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sSpear) + ", " +
			context.getString(R.string.sStaff);
			break;
		case ParentJob.BATTLESUIT	:
			weapons = context.getString(R.string.sProficiencies) +
			context.getString(R.string.sFist) + ", " +
			context.getString(R.string.sGun) + ", " +
			context.getString(R.string.sAxe);
			break;
		case ParentJob.ANDROID		:
			weapons = context.getString(R.string.sProficiencies) + "???";
			break;
		case ParentJob.SLUDGE		:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sSpear);
			break;
		case ParentJob.ORC			:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sSword);
			break;
		case ParentJob.MOTHMAN		:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sGun);
			break;
		case ParentJob.SHROOM		:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sAxe);
			break;
		case ParentJob.GHOST		:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sStaff);
			break;
		case ParentJob.SLUMBERCAT	:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sGun);
			break;
		case ParentJob.PRINNY		:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sBow);
			break;
		case ParentJob.ZOMBIE		:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sBow);
			break;
		case ParentJob.GARGOYLE		:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sAxe);
			break;
		case ParentJob.FLORABEAST	:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sStaff);
			break;
		case ParentJob.ROC			:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sSpear);
			break;
		case ParentJob.REAPER		:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sBow);
			break;
		case ParentJob.MYSTICBEAST	:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sFist);
			break;
		case ParentJob.SUCCUBUS		:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sSword);
			break;
		case ParentJob.DRAGONZOMBIE	:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sSpear);
			break;
		case ParentJob.WOODGOLEM	:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sAxe);
			break;
		case ParentJob.DRAGON		:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sSword);
			break;
		case ParentJob.FELYNN		:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sFist);
			break;
		case ParentJob.RIFLEDEMON	:
			weapons = context.getString(R.string.sMagichange) +
			context.getString(R.string.sGun);
			break;
		}
		if(weapons == null || weapons.isEmpty())
			weapons = "";
	}
	
	/**
	 * Return the character portrait from the sprite sheet based on the selected item in the list
	 * @param index
	 * @return the new cropped segment of the spritesheet
	 */
	public Bitmap getPortrait(int index)
	{
		if(portrait != null)
			return portrait.getTile(index);
		else return null;
	}
	
	/**
	 * Retrieve the icon at tilesheet index number
	 * @param index Index, starting at 0, of the tilesheet
	 * @return 96x96 icon
	 */
	public Bitmap getIcon(int index) { return icon.getTile(index); }
	
	/**
	 * We don't know the index, automatically look it up based on the parent job and class
	 * @return 96x96 icon
	 */
	public Bitmap getIcon() { return icon.getTile(charClass - jobParent); }
	public void updatePortrait(AssetManager assets) throws IOException	{ portrait = ImageFactory.createPortrait(assets, jobParent); }
	public void updateIcon(AssetManager assets) throws IOException	{ icon = ImageFactory.createIcon(assets, jobParent); }
}
